#pragma once

#include <string>
#include "sgx_error.h"
#include "sgx_urts.h"

class EnclaveProvider
{
public:
    EnclaveProvider();
	EnclaveProvider(sgx_enclave_id_t enclave_id);
    ~EnclaveProvider();

    int createEnclave(const std::string &id);

    void destroyEnclave();

	int initVault(sgx_enclave_id_t enclave_id, const std::string &id);

	void uninitVault(sgx_enclave_id_t enclave_id);

	int encrypt_size(int buf_len);

    int encrypt(const char *in_buf, int in_buf_len, char *out_buf, int out_buf_size);
	
	int encryptex(const char *in_buf, int in_buf_len, const int *value_lens, const int *value_types, int value_count, char *out_buf, int out_buf_size, int *out_value_lens);

    int decrypt(const char *in_buf, int in_buf_len, char *out_buf, int out_buf_size);

    int public_key_encrypt(const char *in_buf, int in_buf_len, char *out_buf, int out_buf_size);

    int private_key_decrypt(const char *in_buf, int in_buf_len, char *out_buf, int out_buf_size);

    int private_key_encrypt(const char *in_buf, int in_buf_len, char *out_buf, int out_buf_size);

    int public_key_decrypt(const char *in_buf, int in_buf_len, char *out_buf, int out_buf_size);

	int sign(const char* in_buf, int in_buf_len, char* out_buf, int out_buf_size);

	int sha256_encrytp(const char* in_buf, int in_buf_len, char* out_buf, int out_buf_size);

	bool crypto_key(std::string &key);

public:
	std::string id_;
	sgx_enclave_id_t enclave_id_;

private:
    std::wstring name_ = L"Vault.signed.dll";

    sgx_launch_token_t launch_token_ = { 0 };
    int launch_token_updated_ = 0;
};

